﻿using Com.Aote.Behaviors;
using Com.Aote.ObjectTools;
using Com.Aote.Utils;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Com.Aote.Pages
{
	public partial class 机表票证补打 : UserControl
	{
        public 机表票证补打()
		{
			// Required to initialize variables
			InitializeComponent();
		}

        private void save_Click(object sender, RoutedEventArgs e)
        {
            GeneralObject LoginUserfapiao = (GeneralObject)FrameworkElementExtension.FindResource(this.save, "LoginUserfapiao");
            LoginUserfapiao.DataLoaded += LoginUserfapiao_DataLoaded;
            LoginUserfapiao.Load();
        }

        void LoginUserfapiao_DataLoaded(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            GeneralObject LoginUserfapiao = sender as GeneralObject;
            LoginUserfapiao.DataLoaded -= LoginUserfapiao_DataLoaded;
            if (e.Error != null)
            {
                MessageBox.Show("没有分配发票号，不能预存！");
                return;
            }
            string fapiaohao = LoginUserfapiao.GetPropertyValue("fapiaohao") + "";
            if (string.IsNullOrEmpty(fapiaohao))
            {
                MessageBox.Show("没有分配发票号，不能打印！");
                return;
            }
            print.TipCompleted += print_TipCompleted;
            print.TipNoPrint();
        }

        void print_TipCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            print.TipCompleted -= print_TipCompleted;
            GeneralObject kbfee = userfile.DataContext as GeneralObject;
            string f_invoicenum = kbfee.GetPropertyValue("f_invoicenum") + "";
            GeneralObject fapiao = (GeneralObject)FrameworkElementExtension.FindResource(this.save, "fapiao");
            fapiao.SetPropertyValue("f_fapiaostatue", "作废", true);

            GeneralObject fpinfosobj = (GeneralObject)FrameworkElementExtension.FindResource(this.save, "fpinfosobj");
            fpinfosobj.SetPropertyValue("f_fapiaostatue", "已用", true);

            GeneralObject sellinggas = (GeneralObject)FrameworkElementExtension.FindResource(this.save, "sellinggas");
            sellinggas.SetPropertyValue("f_invoicenum", f_invoicenum, true);

            MessageBox.Show("当前打印发票号：" + f_invoicenum);

            BatchExcuteAction SaveAction = (BatchExcuteAction)FrameworkElementExtension.FindResource(this.save, "SaveAction");
            SaveAction.Invoke();

            print.UseDefaultPrinter = true;
            //print.Completed += print_Completed;
            print.Print();
        }

        void print_Completed(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            print.Completed -= print_Completed;
        }
	}
}